/**
 * \class ExpRegistry.cpp /GenProg/Helpers/ExpRegistry.cpp
 *
 *  \date 16 maj 2012
 *  \author ytc0039
 *  
 *  \brief 
 */

#include "ExpRegistry.h"

ExpRegistry::ExpRegistry() {


}

ExpRegistry::~ExpRegistry() {

}


bool ExpRegistry::addGenFun(TerminalState state,ExpressionType expType,TGenPtr genObj)
{
	bool ret = false;
	TStateMap::iterator iter = m_GenFunMap.find(state);
	if(iter == m_GenFunMap.end() )
	{
		TGenFunTypeMap newMap;
		newMap[expType] = genObj;
		m_GenFunMap[state] = newMap;
		ret = true;
	}else
	{
		pair< TGenFunTypeMap::iterator,bool > retInsert;
		retInsert = (*iter).second.insert(TGenFunTypeMap::value_type(expType,genObj));

		if( retInsert.second )
		{
			ret = true;
		}

	}

	return ret;
}

bool ExpRegistry::getAll(TerminalState state,TGenFunTypeMap& outMap) const
{
	bool ret = false;
	TStateMap::const_iterator iter = m_GenFunMap.find(state);
	if( iter != m_GenFunMap.end() )
	{
		ret = true;
		outMap = (*iter).second;
	}

	return ret;
}



